<!--个人空间-->
<template>
    <div id="app">
        <page-header-white @getInfo="getInfo" @getBack="getBack"/>
        <div class="main">
            <div class="main-info">
                <div class="user">
                    <img v-if="userData.userImgUrl" :src="userData.userImgUrl" class="user-logo" alt="">
                    <img v-else src="@assets/touxiang.png" class="user-logo" alt="">
                    <div class="user-name">{{userData.nickName}}</div>
                    <div class="user-desc">已发布{{total}}篇文章</div>
                </div>
                <div class="list">
                    <div class="list-title">
                        <img src="@assets/my-article.png" alt="">
                        <span>我的文章</span>
                    </div>
                    <div class="list-item" @click="handleEdit(2)">写攻略</div>
                    <div class="list-item" @click="handleEdit(3)">写笔记</div>
                    <div class="list-item" @click="handleEditVideo">发视频</div>
                </div>
            </div>
            <div class="main-list">
                <div class="article-nav">
                    <ArticleNav @handleSelect="handleSelect" :nav-index="navIndex"></ArticleNav>
                </div>
                <keep-alive>
                    <component :is="currentView"></component>
                </keep-alive>
            </div>
        </div>
        
        <div class="login-shadow" v-if="showLogin" @click="closeModal">
            <Login class="login-main"></Login>
        </div>
        
    </div>
</template>

<script>
    import PageHeaderWhite from '@views/PageHeaderWhite'
    import Login from '@views/Login'
    import ArticleNav from '@views/ArticleNav'
    import ArticleStrategy from '@views/articleList/ArticleStrategy'
    import ArticleBox from '@views/articleList/ArticleBox'
    import ArticleNote from '@views/articleList/ArticleNote'
    import VideoNote from '@views/articleList/VideoNote'
    import {getQueryString} from '@utils/utils'
    
    export default {
        name: 'app',
        data() {
            return {
                ios: false,
                android: false,
                showLogin: false,
                pageNum: 1,
                articleList: [],
                haveNextPage: true,
                total: 0,
                userData: {},
                navIndex: Number(getQueryString('navIndex')) || 0,
                componentsList: [
                    {
                        articleType: 2,
                        name: 'ArticleStrategy'
                    },
                    {
                        articleType: 3,
                        name: 'ArticleNote'
                    },
                    {
                        articleType: 4,
                        name: 'VideoNote'
                    },
                    {
                        articleType: 11,
                        name: 'ArticleBox'
                    }
                ],
            }
        },
        computed: {
            currentView() {
                return this.componentsList[this.navIndex].name
            }
        },
        components: {
            PageHeaderWhite, Login, ArticleNav, ArticleStrategy, ArticleNote, VideoNote, ArticleBox
        },
        methods: {
            /* initData(num, articleType) {
				 this.$axios({actionName: 'search.myArticle', pageNum: num, pageSize: 12, articleType}).then(res => {
					 let data = res.data
					 this.articleList = data.article
					 this.haveNextPage = data.haveNextPage
					 this.total = data.total
					 console.log(data.tolal, 'total')
				 })
			 },*/
            mouseover(type) {
                if (type === 'ios') {
                    this.ios = true
                } else {
                    this.android = true
                }
            },
            mouseLeave(type) {
                if (type === 'ios') {
                    this.ios = false
                } else {
                    this.android = false
                }
            },
            handleClick() {
                this.showLogin = true
                // document.body.style.overflow = 'hidden'
            },
            closeModal(event) {
                let login = document.querySelector(".login-main")
                if (login) {
                    if (!login.contains(event.target)) {
                        this.showLogin = false
                        // document.body.style.overflow = ''
                    }
                }
            },
            getInfo(data, total) {
                this.userData = data
                this.total = total
            },
            getBack() {
                window.location.href = './index.html'
            },
            handleSelect(index) {
                // this.currentView = this.componentsList[index].name
                this.navIndex = index
            },
            handleEdit(type) {
                window.location.href = '/editPage.html?articleType=' + type
            },
            handleEditVideo() {
                window.location.href = '/editVideoPage.html'
            },
            handleDelete() {
                this.total -= 1
            },
        }
    }
</script>

<style lang="less">
    html {
        background-color: rgba(0, 0, 0, .04);
    }
    
    #app {
        position: relative;
        width: 100%;
        height: 100%;
        min-width: 1128px;
        background-color: rgba(0, 0, 0, .04);
        -webkit-background-size: cover;
        background-size: cover;
        
        .main {
            width: 1128px;
            z-index: 99;
            margin: 16px auto 0;
            .flexed(center, flex-start);
            
            .main-info {
                width: 216px;
                margin-right: 12px;
                
                .user {
                    width: 100%;
                    padding: 38px 0 32px;
                    margin-bottom: 16px;
                    background: rgba(255, 255, 255, 1);
                    border-radius: 4px;
                    
                    .user-logo {
                        display: block;
                        width: 88px;
                        height: 88px;
                        margin: 0 auto 27px;
                        border-radius: 50%;
                    }
                    
                    .user-name {
                        height: 22px;
                        margin-bottom: 8px;
                        font-size: 16px;
                        font-weight: 500;
                        color: rgba(0, 0, 0, 1);
                        line-height: 22px;
                        text-align: center;
                    }
                    
                    .user-desc {
                        height: 20px;
                        font-size: 14px;
                        font-weight: 400;
                        color: rgba(0, 0, 0, .4);
                        line-height: 20px;
                        text-align: center;
                    }
                }
                
                .list {
                    width: 216px;
                    padding-bottom: 10px;
                    background: rgba(255, 255, 255, 1);
                    border-radius: 4px;
                    opacity: 0.8;
                    
                    .list-title {
                        .flexed(flex-start);
                        height: 40px;
                        margin-bottom: 10px;
                        font-size: 14px;
                        font-weight: bold;
                        color: rgba(0, 0, 0, 1);
                        border-left: 4px solid rgba(255, 220, 32, 1);
                        cursor: pointer;
                        
                        img {
                            margin: 0 8px 0 27px;
                            width: 13px;
                            height: auto;
                        }
                        
                        &:hover {
                            background-color: rgba(255, 220, 32, 1);
                        }
                    }
                    
                    .list-item {
                        width: 216px;
                        height: 40px;
                        padding-left: 50px;
                        /*margin-left: 50px;*/
                        /*margin-bottom: 20px;*/
                        font-size: 14px;
                        color: rgba(0, 0, 0, 1);
                        line-height: 40px;
                        cursor: pointer;
                        
                        &:last-child {
                            margin-bottom: 0;
                        }
                        
                        &:hover {
                            background-color: rgba(255, 220, 32, 1);
                        }
                    }
                }
            }
            
            .main-list {
                width: 900px;
            }
        }
        
        .bottom {
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
        }
        
        .login-shadow {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, .4);
            z-index: 9999;
        }
    }
</style>
